package com.tfr.rabbitmq.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Description:
 * @ClassName: CreateController
 * @Author: Rain
 * @Date: 2021-10-19 19:50
 * @Version: 1.0
 **/
@Slf4j
public class CreateController {
    
    @Autowired
    AmqpAdmin amqpAdmin;
    
    /**
     * @Author: Rain
     * @Description: 创建交换机
     * @Date: 2021/10/19 19:55
     * @Param:
     * @return: void
     **/
    @GetMapping("createTopicExchange")
    public void createTopicExchange() {
        TopicExchange topicExchange = new TopicExchange("test-Exchange");
        amqpAdmin.declareExchange(topicExchange);
        log.info("createTopicExchange success...");
    }
    
    /**
     * @Author: Rain
     * @Description: 创建队列
     * @Date: 2021/10/19 19:57
     * @Param:
     * @return: void
     **/
    @GetMapping("createQueue")
    public void createQueue() {
        Queue queue = new Queue("test-queue");
        amqpAdmin.declareQueue(queue);
        log.info("queue success...");
    }
    
    
    @GetMapping("createBinding")
    public void createBinding() {
        Binding binding = new Binding(
                "test-queue",
                Binding.DestinationType.QUEUE,
                "test-Exchange",
                "nihao.tfr", null);
        amqpAdmin.declareBinding(binding);
    }
    
}